<include file="Common/header" />
<title>费用详情</title>
<script type="text/javascript" src="__PUBLIC__/h-ui/lib/jquery/1.9.1/jquery.form.js"></script>
</head>
<body>
<div class="pd-20">
	<form action="" method="post" class="form form-horizontal" id="form-user-character-add" enctype="multipart/form-data">
		<div class="panel panel-primary">
			<div class="panel-header">基本信息</div> 
			<table class="table table-border table-bordered table-striped">
	            <tr>
					<td style="background-color: #f9f9f9;text-align: right" width="10%">客人姓名：</td>
	                <td style="background-color: white" width="10%">
						<input type="hidden" name="logid" id="logid" value="{$info['id']}" />
						<input type="text" class="input-text radius" value="{$info['nickname']}" readonly />
					</td>
	                <td style="background-color: #f9f9f9;text-align: right" width="10%">合同编号：</td>
	                <td style="background-color: white;" width="10%">
						<input type="text" class="input-text radius" style="width:180px;" value="{$info['contract']}" readonly />
					</td>
					<td style="background-color: #f9f9f9;text-align: right" width="10%">房间编号：</td>
	                <td style="background-color: white;">
						<input type="text" class="input-text radius" style="width:180px;" value="{$info['roomnumber']}" readonly />
					</td>
	            </tr>
				<tr>
					<td style="background-color: #f9f9f9;text-align: right">状态：</td>
	                <td style="background-color: white;">
						<span class="select-box radius" style="width: 80px;">
							<select id="visible" name="visible" class="select radius">
								<option value="1" {$info['visible'] == 1 ? 'selected' : ''}>有效</option>
								<option value="0" {$info['visible'] == 0 ? 'selected' : ''}>无效</option>
							</select>
						</span>
						<input type="hidden" name="o_visible" id="o_visible" value="{$info['visible']}" />
					</td>
					<td style="background-color: #f9f9f9;text-align: right; ">缴费时间：</td>
					<td style="background-color: white">
						<span class="select-box radius">
							<input type="text" name="createtime" id="createtime" class="select layer-date radius time" value="<?php echo date('Y-m-d H:i',$info['createtime']);?>" />
						</span>
					</td>
					<td style="background-color: #f9f9f9;text-align: right; ">备注：</td>
					<td style="background-color: white">
						<input type="text" name="remark" id="remark" class="input-text radius" value="{$info['remark']}" />
					</td>
				</tr>
			</table>
		</div>
		
		<div class="panel panel-primary mt-5">
			<div class="panel-header">费用详情</div> 
			<table class="table table-border table-bordered table-striped">
	            <tr>
					<td style="background-color: #f9f9f9;text-align: right">房租：</td>
	                <td style="background-color: white">
						<input type="text" class="input-text radius" value="{$info['rent']}" readonly />
					</td>
	                <td style="background-color: #f9f9f9;text-align: right">物业：</td>
	                <td style="background-color: white;">
						<input type="text" class="input-text radius" style="width:180px;" value="{$info['property']}" readonly />
					</td>
					<td style="background-color: #f9f9f9;text-align: right">押金：</td>
	                <td style="background-color: white;">
						<input type="text" class="input-text radius keyups" name="deposit" id="deposit" style="width:180px;" value="{$info['deposit']}" />
					</td>
	            </tr>
				<tr>
					<td style="background-color: #f9f9f9;text-align: right">定金：</td>
	                <td style="background-color: white">
						<input type="text" class="input-text radius keyups" id="deposit_first" name="deposit_first" value="{$info['deposit_first']}" />
					</td>
	                <td style="background-color: #f9f9f9;text-align: right">水费：</td>
	                <td style="background-color: white;">
						<input type="text" class="input-text radius keyups" id="water_power" name="water_power" style="width:180px;" value="{$info['water_power']}" />
					</td>
					<td style="background-color: #f9f9f9;text-align: right">电费：</td>
	                <td style="background-color: white;">
						<input type="text" class="input-text radius keyups" name="electric" id="electric" style="width:180px;" value="{$info['electric']}" />
					</td>
	            </tr>
				<tr>
					<td style="background-color: #f9f9f9;text-align: right">房卡押金：</td>
	                <td style="background-color: white">
						<input type="text" class="input-text radius keyups" id="card_deposit" name="card_deposit" value="{$info['card_deposit']}" />
					</td>
	                <td style="background-color: #f9f9f9;text-align: right">其他：</td>
	                <td style="background-color: white;">
						<input type="text" class="input-text radius keyups" id="other" name="other" style="width:180px;" value="{$info['other']}" />
					</td>
					<td style="background-color: #f9f9f9;text-align: right">总计：</td>
	                <td style="background-color: white;">
						<input type="text" class="input-text radius" name="acount" id="acount" style="width:180px;" value="{$info['acount']}" />
					</td>
	            </tr>
	        </table>
		</div>
		<div class="panel panel-primary mt-5">
			<div class="panel-header">支付方式</div>
			<table class="table table-border table-bordered table-striped">
	            <tr>
					<td style="background-color: #f9f9f9;text-align: right;width: 70px;">现金：</td>
	                <td style="background-color: white">
						<input type="text" name="xianjin" id="xianjin" class="input-text radius" value="{$info['xianjin']}" />
					</td>
	                <td style="background-color: #f9f9f9;text-align: right;width: 70px;">POS机：</td>
	                <td style="background-color: white;">
						<input type="text" class="input-text radius" name="lakala" id="lakala" value="{$info['lakala']}" />
					</td>
					<td style="background-color: #f9f9f9;text-align: right;width: 70px;">信用卡：</td>
	                <td style="background-color: white;">
						<input type="text" class="input-text radius" name="band" id="band" value="{$info['band']}" />
					</td>
					<td style="background-color: #f9f9f9;text-align: right;width: 70px;">转账：</td>
	                <td style="background-color: white;">
						<input type="text" class="input-text radius" name="zhuanzhang" id="zhuanzhang" value="{$info['zhuanzhang']}" />
					</td>
	            </tr>
				<tr>
					<td style="background-color: #f9f9f9;text-align: right">支付宝：</td>
	                <td style="background-color: white">
						<input type="text" name="alipay" id="alipay" class="input-text radius" value="{$info['alipay']}" />
					</td>
					<td style="background-color: #f9f9f9;text-align: right">订单号：</td>
	                <td style="background-color: white;" colspan="5">
						<input type="text" class="input-text radius" name="alipay_ordersn" id="alipay_ordersn" value="{$info['alipay_ordersn']}" />
					</td>
	            </tr>
				<tr>
					<td style="background-color: #f9f9f9;text-align: right">微信：</td>
	                <td style="background-color: white">
						<input type="text" name="weixin" id="weixin" class="input-text radius" value="{$info['weixin']}" />
					</td>
					<td style="background-color: #f9f9f9;text-align: right">订单号：</td>
	                <td style="background-color: white;" colspan="5">
						<input type="text" class="input-text radius" name="weixin_ordersn" id="weixin_ordersn" value="{$info['weixin_ordersn']}" />
					</td>
	            </tr>
	        </table>    
		</div>

		<div class="mt-5 mb-5 text-c">
			<button type="button" class="btn btn-success radius submitBtn" id="admin-role-save" name="admin-role-save">
				<i class="icon-ok"></i> 确定
			</button>
		</div>
	</form>
</div>
<script>
	$(document).ready(function(){
		//设置时间控件
		$(".time").on('click', function(){
			laydate({istime: true, format: 'YYYY-MM-DD hh:mm'});
		});
		
		//动态金额计算
		$(".keyups").on('keyup', function(event){
			var vals = $(this).val() || 0;
			//1. 判断是否为数字
			if(!isNaN(vals)){
				var acount = 0;
				//获取所有选中的checkbox
				$(".keyups").each(function(e){
					var thisCountVal = $(this).val();
					acount += parseFloat(thisCountVal);
				});

				$("#acount").val(acount.toFixed(2));
			}
		});
		
		/**
		 * 提交数据
		 **/
		$(".submitBtn").on('click', function(){
			var fromData = {};
				fromData.deposit = $("#deposit").val();
				fromData.deposit_first = $("#deposit_first").val();
				fromData.water_power = $("#water_power").val();
				fromData.electric = $("#electric").val();
				fromData.card_deposit = $("#card_deposit").val();
				fromData.other = $("#other").val();
				fromData.acount = $("#acount").val();
				fromData.createtime = $("#createtime").val();
			//判断支付方式
			var xianjin = $("#xianjin").val();
			var lakala = $("#lakala").val();
			var band = $("#band").val();
			var alipay = $("#alipay").val();
			var weixin = $("#weixin").val();
			var zhuanzhang = $("#zhuanzhang").val();
				fromData.xianjin = xianjin;
				fromData.zhuanzhang = zhuanzhang;
				fromData.lakala = lakala;
				fromData.band = band;
				fromData.alipay = alipay;
				fromData.weixin = weixin;
				fromData.alipay_ordersn = $("#alipay_ordersn").val();
				fromData.weixin_ordersn = $("#weixin_ordersn").val();
				fromData.remark = $("#remark").val();
				fromData.visible = $("#visible").val();
			//判断总金额是否一致
			if((xianjin/1 + lakala/1 + band/1 + alipay/1 + weixin/1 + zhuanzhang/1) != fromData.acount){
				layer.msg('支付金额分配错误，请重新分配。', {icon: 5, time: 2000});
				return false;
			}
			
			//判断是否需要输入密码
			if(fromData.visible/1 != $("o_visible").val()/1){
				var html = '<input type="password" name="pwds" id="pwds" class="input-text radius" />';
				var i = layer.open({
					title: '验证管理员密码',
					content: html,
					yes: function(){
						var password = $("#pwds").val();
						if(password.length > 0){
							fromData.pwds = password;
						}else{
							layer.msg('请输入管理员密码', {icon: 5, time: 2000});
							return;
						}
						
						layer.close(i);
						submitFormData($("#logid").val(), fromData);
					}
				});
			}else{
				submitFormData($("#logid").val(), fromData);
			}
		});
	});
	
	/**
	 * 提交数据
	 **/
	var submitFormData = function(logid, fromData){
		var load = layer.load(2);
		$.post('edit.html', {logid: logid, json: JSON.stringify(fromData)}, function(data){
			layer.close(load);
			if(data/1 == 1){
				layer.msg('操作成功', {icon: 1, time: 2000}, function(){
					window.parent.location.reload(); //刷新
					var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
					parent.layer.close(index);
				});
			}else if(data/1 == 2){
				layer.msg('管理员密码错误', {icon: 5, time: 2000});
			}else{
				layer.msg('操作失败', {icon: 2, time: 2000});
			}
		});
	}
</script>
</body>
</html>